import abstraction.*;
import implementor.*;
import org.opencv.core.Core;
import java.io.File;

public class ImageProcessor {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
    
    public static void main(String[] args) {
        System.out.println("图像处理程序启动...");

        testImageFilters();
    }
    
    private static void testImageFilters() {
        String jpgPath = "e:\\Shiyan6Q2\\src\\main\\resources\\test1.jpg";
        String bmpPath = "e:\\Shiyan6Q2\\src\\main\\resources\\test2.bmp";
        String outputDir = "e:\\Shiyan6Q2\\output\\";

        Filter blurFilter = new BlurFilter();
        Filter sharpenFilter = new SharpenFilter();
        Filter cutoutFilter = new CutoutFilter();
        Filter textureFilter = new TextureFilter();
        Filter cannyFilter = new CannyEdgeFilter();

        System.out.println("\n===== 处理JPG图像 =====");
        processImageWithFilters(new JPGImage(jpgPath), outputDir, "jpg", 
                blurFilter, sharpenFilter, cutoutFilter, textureFilter, cannyFilter);

        System.out.println("\n===== 处理BMP图像 =====");
        processImageWithFilters(new BMPImage(bmpPath), outputDir, "bmp", 
                blurFilter, sharpenFilter, cutoutFilter, textureFilter, cannyFilter);
    }
    
    private static void processImageWithFilters(Image image, String outputDir, String extension, Filter... filters) {
        System.out.println("\n处理" + image.getType() + "图像:");
        System.out.println(image.getInfo());

        File dir = new File(outputDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        
        for (Filter filter : filters) {
            image.setFilter(filter);
            String filterName = filter.getName();
            String outputPath = outputDir + image.getType() + "_" + filterName + "." + extension;
            System.out.println("保存文件: " + outputPath);
            image.processAndSave(outputPath);
        }
    }
}